<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    <title>ShellCheck: SC2147 – Literal tilde in PATH works poorly across programs.</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
  </head>
  <body style="margin-left: auto; margin-right: auto; max-width: 800px">
    <h1>SC2147 – ShellCheck Wiki</h1>
    <a href="https://github.com/koalaman/shellcheck/wiki/SC2147">See this page on GitHub</a>
    <p style="display: none"><a href="index.html">Sitemap</a></p>
    <hr />
    <h2 id="literal-tilde-in-path-works-poorly-across-programs">Literal
tilde in PATH works poorly across programs.</h2>
<h3 id="problematic-code">Problematic code:</h3>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="SC2147.html#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="va">PATH</span><span class="op">=</span><span class="st">&quot;</span><span class="va">$PATH</span><span class="st">:~/bin&quot;</span></span></code></pre></div>
<h3 id="correct-code">Correct code:</h3>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="SC2147.html#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="va">PATH</span><span class="op">=</span><span class="st">&quot;</span><span class="va">$PATH</span><span class="st">:</span><span class="va">$HOME</span><span class="st">/bin&quot;</span></span></code></pre></div>
<h3 id="rationale">Rationale:</h3>
<p>Having literal <code>~</code> in PATH is a bad idea. Bash handles it,
but nothing else does.</p>
<p>This means that even if you're always using Bash, you should avoid it
because any invoked program that relies on PATH will effectively ignore
those entries.</p>
<p>For example, <code>make</code> may say
<code>foo: Command not found</code> even though <code>foo</code> works
fine from the shell and Make and Bash both use the same PATH. You'll get
similar messages from any non-bash scripts invoked, and
<code>whereis</code> will come up empty.</p>
<p>Use <code>$HOME</code> or full path instead.</p>
<h3 id="exceptions">Exceptions</h3>
<p>If your directory name actually contains a literal tilde, you can
ignore this message.</p>
    <hr />
    <p style='font-size: 80%'><a href="../index.html">ShellCheck</a> is a static analysis tool for shell scripts. This page is part of its documentation.</p>
  </body>
</html>


